#include "../source/server.hpp"

void OnConnected(const PtrConnection &conn)
{
    DLOG("new connection: %p", conn.get());
}

void OnClosed(const PtrConnection &conn)
{
    DLOG("close connection: %p", conn.get());
}

void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    DLOG("%s", buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "hello world";
    conn->Send(str.c_str(), str.size());
    conn->Shutdown();
}

int main()
{
    TcpServer server(8080);
    // 设置线程的数量
    server.SetThreadCount(2);
    // 启动超时销毁
    server.EnableInactiveRelease(10);
    
    // 设置回调函数
    server.SetMessageCallback(OnMessage);
    server.SetConnectedCallback(OnConnected);
    server.SetClosedCallback(OnClosed);

    // 启动服务器
    server.Start();
    return 0;
}